# routers/image_router.py
import io
from datetime import datetime, timedelta
from PIL import Image
from fastapi import APIRouter, UploadFile, File, Depends, Form

from core.dependencies import get_minio_client
from db.models.users import UserDocument
from core.security import get_current_active_user
from services.gridfs_service import get_gridfs
from services.image_service import get_image_service
from utils.minio_util import put_image
from utils.result import Result

router = APIRouter()


@router.post("/images")
async def upload_image(
        to_user_name: str = Form(...),  # 使用 Form(...) 来接收表单字段
        file: UploadFile = File(...),
        current_user: UserDocument = Depends(get_current_active_user),
        image_service = Depends(get_image_service)
):
    """上传图片"""
    return await image_service.upload_image(file=file, to_user_name=to_user_name, current_user=current_user)


@router.get("/images")
async def get_image(filename: str, current_user: UserDocument = Depends(get_current_active_user),image_service = Depends(get_image_service)):
    """获取图片"""
    return await image_service.get_image(filename=filename, user=current_user)
